#include <iostream>
#define LL long long
using namespace std;

const int kMaxN = 1e5 + 10;
const int kMaxLCMP = 3 * 5 * 7 * 8;

int p[kMaxN], t[kMaxN];
int n, X, Y;
LL ans[kMaxLCMP];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> X >> Y;

  for (int i = 1; i < n; i++) {
    cin >> p[i] >> t[i];
  }
  for (int st = 0; st < kMaxLCMP; st++) {
    LL& now = ans[st];

    now = st + X;
    for (int i = 1; i < n; i++) {
      if (now % p[i] != 0) {
        now += p[i] - now % p[i];
      }
      now += t[i];
    }
    now += Y;
  }

  int q;
  for (cin >> q; q; q--) {
    int st;

    cin >> st;
    cout << ans[st % kMaxLCMP] + st - st % kMaxLCMP << "\n";
  }
  return 0;
}